package com.fitnessrocks.sweattimer.data;

import android.content.Context;

import com.fitnessrocks.sweattimer.R;

public class CountdownTimer extends AbstractTimer {

    private final long mTotalDurationInMillis;

    protected CountdownTimer(Context context, long durationInMillis) {
        super(context, context.getString(R.string.timer_countdown_name));

        mTotalDurationInMillis = durationInMillis;
    }

    @Override
    public long getIntervalDuration(int intervalIndex) {
        return mTotalDurationInMillis;
    }

    @Override
    public int getIntervalIndex(long timeInMillis) {
        if (timeInMillis < 0 || timeInMillis >= mTotalDurationInMillis) {
            return -1;
        }
        return 0;
    }

    @Override
    public long getIntervalTimeLapsed(long timeInMillis) {
        return timeInMillis;
    }

    @Override
    public long getIntervalTimeLeft(long timeInMillis) {
        return mTotalDurationInMillis - timeInMillis;
    }

    @Override
    public IntervalType getIntervalType(int intervalIndex) {
        if (intervalIndex != 0) {
            return IntervalType.OTHER;
        }
        return IntervalType.WORK;
    }

    @Override
    public int getSessionIndex(long timeInMillis) {
        if (timeInMillis < 0 || timeInMillis >= mTotalDurationInMillis) {
            return -1;
        }
        return 0;
    }

    @Override
    public String getSessionName(int sessionIndex) {
        return mContext.getString(R.string.timer_countdown_name);
    }

    @Override
    public long getSessionTimeLapsed(long timeInMillis) {
        return timeInMillis;
    }

    @Override
    public long getSessionTimeLeft(long timeInMillis) {
        return mTotalDurationInMillis - timeInMillis;
    }

    @Override
    public long getTotalDuration() {
        return mTotalDurationInMillis;
    }

    @Override
    public int getTotalIntervals() {
        return 1;
    }

    @Override
    public int getTotalIntervalsLapsed(int intervalIndex) {
        return 0;
    }

    @Override
    public int getTotalIntervalsLeft(int intervalIndex) {
        return 1;
    }

    @Override
    public int getTotalSessions() {
        return 1;
    }

    @Override
    public int getTotalSessionsLapsed(int sessionIndex) {
        return 0;
    }

    @Override
    public int getTotalSessionsLeft(int sessionIndex) {
        return 1;
    }

    @Override
    public long getTotalTimeLapsed(long timeInMillis) {
        return timeInMillis;
    }

    @Override
    public long getTotalTimeLeft(long timeInMillis) {
        return mTotalDurationInMillis - timeInMillis;
    }

}
